package com.example.guiguihomemedical.service.impl;

import com.example.guiguihomemedical.entity.Record;
import com.example.guiguihomemedical.entity.dto.RecordList;
import com.example.guiguihomemedical.mapper.RecordMapper;
import com.example.guiguihomemedical.service.RecordListService;
import com.example.guiguihomemedical.service.RecordSearchService;
import com.example.guiguihomemedical.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;
    @Autowired
    private RecordListService recordListService;

    @Override
    public void addRecord(Record record) {
        // 在这里你可以添加一些逻辑，比如设置一些默认值或者进行参数校验

        // 调用 RecordMapper 中的插入方法将记录添加到数据库
        recordMapper.insertRecord(record);
    }

    @Override
    public void updateRecord(Record record) {
        // 在这里你可以添加一些逻辑，比如进行参数校验

        // 调用 RecordMapper 中的更新方法更新记录到数据库
        recordMapper.updateRecord(record);
    }
    @Override
    public void updateRecord_h(Record record){
        recordMapper.updateRecord_h(record);
    }
    @Override
    public void deleteRecordById(String idcard) {
        // 在这里你可以添加一些逻辑，比如进行参数校验

        // 调用 RecordMapper 中的删除方法删除记录
        recordMapper.deleteRecordById(idcard);
    }

    @Override
    public Record findByIdcard(String idcard) {
        return recordMapper.findByIdcard(idcard);
    }

    @Override
    public List<Record> findAllRecords() {
        return recordMapper.findAllRecords();
    }

    @Override
    public List<Record> recordList(String query) {
        return recordMapper.recordList(query);
    }

    @Override
    public RecordList getRecordByIdcard(String idcard) {
        List<RecordList> recordLists = recordListService.getRecordList();
        RecordList CurrentRecordList = new RecordList();
        for(RecordList recordList:recordLists){
            if(recordList.getIdcard().equals(idcard)){
                CurrentRecordList=recordList;
            }
        }
        return CurrentRecordList;
    }
}
